import { Component, OnInit, ViewChild, Output, Input, EventEmitter } from '@angular/core';
const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) };
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
import { Router } from '@angular/router';
import { NzModalRef, NzFormatEmitEvent, NzModalService, NzTreeComponent, NzTreeNodeOptions, NzMessageService } from 'ng-zorro-antd';
import { PagesService } from 'services/pages.service';
import { UtilService } from 'services/util.service';
import { RequestService } from 'services/request.service';
declare var layui: any;
declare var layer: any;
declare var $: any;

@Component({
  selector: 'app-cp-popup',
  templateUrl: './cp-popup.component.html',
  styleUrls: ['./cp-popup.component.scss']
})
export class CpPopupComponent implements OnInit {

  constructor(public router: Router, private http: HttpClient, public interfaceService: PagesService, public utilService: UtilService, public request: RequestService) {

  }

  @Output() private outer = new EventEmitter();
  @Input() module: any;

  ngOnInit() {

  }

  warehCode
  field1 = [];
  data1_parmKey = '';
  tableId = '';
  searchData = {};
  data1_sel = [];
  popupTitle = '数据选择';
  popupUrl = '';
  optionUrl = '';
  popupCheck = '0';
  switchUnitId = '';
  /**
   * 
   * @param key 弹窗动态列标识
   * @param parm 查询列表参数
   * @param title 弹窗文字
   * @param optionUrl 下拉接口地址（组织、人员及无下拉控件弹窗可不传）
   * @param value 验证数值（可选参数，传递正常参数为验证数据模式）
   * @param checkName 是否多选（可选参数，传1为多选原值集合返回，传字段名称为多选赋值字段分割处理后返回）
   */
  brandId = [];
  brandswitchUnitId
  brandswitchUnitId2
  brandpopupUrl
  brandpopupUrl2
  tableShow(key, parm, title, value?, checkName?): void {
    this.popupTitle = title;
    this.data1_parmKey = key;
    this.tableId = key + new Date().getTime() + Math.random().toString(36).substr(2, 15);
    if (this.data1_parmKey === 'UNIT_OPTION') {// 组织
      this.popupUrl = '/erp/unit/option/unitOption';
      this.data1_sel['unitStatus'] = JSON.parse(localStorage.getItem('unitStatus_list'));
    } else if (this.data1_parmKey === 'PRSNL_OPTION') {// 人员
      this.popupUrl = '/erp/user/option/prsnlOption';
      this.data1_sel['prsnlStatus'] = JSON.parse(localStorage.getItem('userStatus_list'));
    } else if (this.data1_parmKey === 'SYS_CRP') {// 自定义报表
      this.popupUrl = '/erp/system/statement/syscrp/querysyscrpbyfilter';
      this.optionUrl = '/erp/system/statement/syscrp/syscrppulldown';
    } else if (this.data1_parmKey === 'PROD_CLS_OPTION') {// 商品品种
      this.popupUrl = '/erp/product/cls/listUnit';
      this.data1_sel['prodStatus'] = JSON.parse(localStorage.getItem('prodStatus_list'));
      this.brandpopupUrl2 = this.popupUrl + parm;
      this.brandswitchUnitId2 = this.interfaceService.GetString2(this.brandpopupUrl2, 'switchUnitId');
      this.interfaceService.postPage("/erp/product/getOption/rhBrand", { switchUnitId: this.brandswitchUnitId2}).subscribe((data: any) => {
        if (this.interfaceService.codeValidation(data)) {
        if (data.code == 200) {
          this.data1_sel['brandId'] = data.object['brandId']
        }
      }
      });
    } else if (this.data1_parmKey === 'DTL_PROD') {// 商品
      this.popupUrl = '/erp/purchase/unitProdCls/billProdlist';
      this.data1_sel['prodStatus'] = JSON.parse(localStorage.getItem('prodStatus_list'));
      this.brandpopupUrl = this.popupUrl + parm;
      this.brandswitchUnitId = this.interfaceService.GetString2(this.brandpopupUrl, 'switchUnitId');
      this.interfaceService.postPage("/erp/product/getOption/rhBrand", { switchUnitId: this.brandswitchUnitId}).subscribe((data: any) => {
        if (this.interfaceService.codeValidation(data)) {
        if (data.code == 200) {
          this.data1_sel['brandId'] = data.object['brandId']
        }
      }
      });
    } 
    else if (this.data1_parmKey === 'BRAND') {// 品牌
      this.popupUrl = '/erp/product/brand/selectAll';
    } else if (this.data1_parmKey === 'PUC') {// 采购合同号
      this.popupUrl = '/erp/purchase/puc/list';
      this.interfaceService.postPage("/erp/purchase/puo/option", {}).subscribe((data: any) => {
        if (this.interfaceService.codeValidation(data)) {
          if (data.code == 200) {
            this.data1_sel['progress'] = data.object['progress']
          }
        }
      });
    } else if (this.data1_parmKey === 'SRC') {// 原始单据
      this.popupUrl = '/erp/sales/src/list';
      this.interfaceService.postPage("/erp/purchase/prc/option", {}).subscribe((data: any) => {
        if (this.interfaceService.codeValidation(data)) {
        if (data.code == 200) {
          this.data1_sel['progress'] = data.object['progress']
        }
      }
      });
    } else if (this.data1_parmKey === 'STT') {// 盘点清单编号
      this.popupUrl = '/erp/warehouse/stl/sttpopup';
      this.warehCode = localStorage.getItem('warehCode');
      this.interfaceService.postPage("/erp/warehouse/stt/loadsttpulldown", {}).subscribe((data: any) => {
        if (this.interfaceService.codeValidation(data)) {
          if (data.code == 200) {
            this.data1_sel['progress'] = data.object['progress']
          }
        }
      });
    } else if (this.data1_parmKey === 'SYS_ROLE') {// 角色
      this.popupUrl = '/erp/user/role/all';
    } else if (this.data1_parmKey === 'PPR_BY_PUC') {// 关联采购合同
      this.popupUrl = '/erp/ppr/relationPucList';
    } else if (this.data1_parmKey === 'PPR_GRN') {// 关联入库单
      this.popupUrl = '/erp/warehouse/grn/pprrelevancegrnpopup';
    } else if (this.data1_parmKey === 'PMN') {// 预付款单号
      this.popupUrl = '/erp/ppr/relationPmnList';
    } else if (this.data1_parmKey === 'PPR') {// 采购付款申请单
      this.popupUrl = '/erp/pprTask/relationPprList';
    } else if (this.data1_parmKey === 'DOMAIN_ACCREDIT_OPTION') {// 授权领域
      this.popupUrl = '/erp/unit/option/unitOption';
    } else if (this.data1_parmKey === '未出动态列模块') {// 领域（还未出动态列模块标识）
      this.popupUrl = '/erp/user/ordinary/getdomain';
    } else if (this.data1_parmKey === 'SLC') {// 销售合同号
      this.popupUrl = '/erp/sales/slc/list';
      this.interfaceService.postPage("/erp/purchase/puc/option", {}).subscribe((data: any) => {//手动下拉
        if (this.interfaceService.codeValidation(data)) {
        if (data.code == 200) {
          this.data1_sel['progress'] = data.object['progress']
        }
      }
      });
    } else if (this.data1_parmKey === 'PROD_CLS') {// 套装代码
        this.popupUrl = '/erp/product/cls/listUnit';
    } else if (this.data1_parmKey === 'PRC') {// 退购合同号
      this.interfaceService.postPage("/erp/purchase/prc/option", {}).subscribe((data: any) => {//手动下拉
        if (this.interfaceService.codeValidation(data)) {
        if (data.code == 200) {
          this.data1_sel['progress'] = data.object['progress']
        }
      }
      });
      this.popupUrl = '/erp/purchase/prc/list';
    } else if (this.data1_parmKey === '未出动态列模块') {// 组织筛选（还未出动态列模块标识）
      this.popupUrl = '/erp/user/ordinary/getdomain';
    } else if (this.data1_parmKey === 'SYS_CUT_DOMAIN') {// 切换领域
      this.popupUrl = '/erp/unit/option/unitOption';
    } else if (this.data1_parmKey === 'SYS_PRIVILEGE') {// 权限
      this.interfaceService.postPage("/erp/user/privilege/privtype", "").subscribe((data: any) => {
        if (this.interfaceService.codeValidation(data)) {
          if (data.code == 200) {
            this.data1_sel['privType'] = data.object;
          }
        }
      });
      this.popupUrl = '/erp/priv/option/privOption';
    } else if (this.data1_parmKey === 'UNIT_DOMAIN') {// 设置密码--领域
      this.popupUrl = '/erp/unit/option/unitOption';
    } else if (this.data1_parmKey === 'PRD_CYCLE_PARAM') {// 商品周期动作参数配置弹窗动作id
      this.popupUrl = '/erp/prdCycleParam/prdCycleParamList';
    } else if (this.data1_parmKey === 'UNIT_PARAMETER') {// 领域组织参数
      this.popupUrl = '/erp/unitParameter/list';
    }else if (this.data1_parmKey === 'SWITCH_DOMAIN') {// 切换组织
      this.popupUrl = '/erp/unitParameter/list';
    }

    this.popupUrl = this.popupUrl + parm;
    this.switchUnitId = this.interfaceService.GetString2(this.popupUrl, 'switchUnitId');
    if (value) {
      let vilidUrl = '';
      if (this.data1_parmKey === 'UNIT_OPTION') {
        vilidUrl = this.popupUrl + '&unitCode=' + value;
      } else if (this.data1_parmKey === 'PRSNL_OPTION') {
        vilidUrl = this.popupUrl + '&prsnlCode=' + value;
      } else if (this.data1_parmKey === 'DTL_PROD') {
        vilidUrl = this.popupUrl + '&prodCode=' + value;
      } else if (this.data1_parmKey === 'PROD_CLS_OPTION') {
        vilidUrl = this.popupUrl + '&prodClsCode=' + value;
      }else if (this.data1_parmKey === 'BRAND') {
        vilidUrl = this.popupUrl + '&brandId=' + value;
      } else if (this.data1_parmKey === 'STT') {
        vilidUrl = this.popupUrl + '&sttNum=' + value;
      }else if (this.data1_parmKey === 'UNIT_DOMAIN') {
        vilidUrl = this.popupUrl + '&unitCode=' + value;
      }
      this.validation(vilidUrl);
    } else {
      if (checkName) {
        this.popupCheck = checkName;
        this.interfaceService.dynamicFieldSelect(this, 1, 'tableList', {}, 1, 'popupShow');
      } else {
        this.interfaceService.dynamicFieldSelect(this, 1, 'tableList', {}, 0, 'popupShow');
      }
    }
  }

  popupShow() {
    this.searchData[this.tableId] = true;
    if (this.optionUrl) {
      this.interfaceService.postPage(this.optionUrl, {}).subscribe((data2: any) => {
        if (this.interfaceService.codeValidation(data2)) {
        if (data2.code == 200) {
          for (let i in data2.object) {
            this.searchData[i] = null
            this.data1_sel[i] = data2.object[i]
          }
        }
      }
      });
    }
  }

  validation(url) {
    this.interfaceService.getPage(url).subscribe((data: any) => {
      if (this.interfaceService.codeValidation(data)) {
        if (data.code != 200) {
          layer.msg(data.message);
        }
        var pdata = data.object
        for (let i in pdata) {
          pdata[i] = pdata[i] == null ? '' : pdata[i];
        }
        this.outer.emit(pdata);
      }
    });
  }

  popupHide(): void {
    this.isPopup = false;
    for (var i in this.searchData) {
      this.searchData[i] = null
    }
    this.searchData[this.tableId] = false;
    this.popupCheck = '0';
  }

  tableList() {
    $('input').blur()
    let para = '';
    if (this.data1_parmKey === 'UNIT_OPTION') {// 组织
      para = '&unitCode=' + this.searchData['unitCode'] + '&unitName=' + this.searchData['unitName'] + '&inputCode=' + this.searchData['inputCode'] + '&unitStatus=' + this.searchData['unitStatus'];
    } else if (this.data1_parmKey === 'PRSNL_OPTION') {// 人员
      para = '&prsnlCode=' + this.searchData['prsnlCode'] + '&prsnlName=' + this.searchData['prsnlName'] + '&mobileNum=' + this.searchData['mobileNum'] + '&prsnlStatus=' + this.searchData['prsnlStatus'];
    } else if (this.data1_parmKey === 'SYS_CRP') {// 自定义报表
      const Status = this.searchData['crpType'] == null ? '' : this.searchData['crpType'];
      para = '&crpId=' + this.searchData['crpId'] + '&crpName=' + this.searchData['crpName'] + '&crpType=popup';
    } else if (this.data1_parmKey === 'PROD_CLS_OPTION') {// 商品品种
      para = '&prodClsCode=' + this.searchData['prodClsCode'] + "&prodName=" + this.searchData['prodName'] + "&prodCatId=" + this.searchData['prodCatId'] + "&inputCode=" + this.searchData['inputCode'] + "&brandId=" + this.searchData['brandId'] + "&prodStatus=" + this.searchData['prodStatus'];
    }else if (this.data1_parmKey === 'DTL_PROD') {// 商品
      para = '&prodCode=' + this.searchData['prodCode'] + "&prodName=" + this.searchData['prodName'] + "&prodCatId=" + this.searchData['prodCatId'] + "&inputCode=" + this.searchData['inputCode'] + "&brandId=" + this.searchData['brandId'] + "&prodStatus=" + this.searchData['prodStatus'];
    } 
    else if (this.data1_parmKey === 'BRAND') {// 品牌
      para = '&brandId=' + this.searchData['brandId'] + "&brandName=" + this.searchData['brandName']
    } else if (this.data1_parmKey === 'PUC') {// 采购合同号
      if (this.searchData['startTime'] == undefined || this.searchData['endTime'] == undefined) {
        this.searchData['startTime'] = ''
        this.searchData['endTime'] = ''
      }
      para = "&pucNum=" + this.searchData['pucNum'] + "&startTime=" + this.searchData['startTime'] + "&endTime=" + this.searchData['endTime'] + "&venderCode=" + this.searchData['venderCode'] + "&vdrWarehCode=" + this.searchData['vdrWarehCode'] + "&vdeWarehCode=" + this.searchData['vdeWarehCode'] + "&progress=" + this.searchData['progress']
    } else if (this.data1_parmKey === 'SRC') {// 原始单据
      if (this.searchData['startTime'] == undefined || this.searchData['endTime'] == undefined) {
        this.searchData['startTime'] = ''
        this.searchData['endTime'] = ''
      }
      para = "&srcNum=" + this.searchData['srcNum'] + "&startTime=" + this.searchData['startTime'] + "&endTime=" + this.searchData['endTime'] + "&vendeeNum=" + this.searchData['vendeeNum'] + "&vdeWarehNum=" + this.searchData['vdeWarehNum'] + "&vdrWarehNum=" + this.searchData['vdrWarehNum'] + "&progress=" + this.searchData['progress'] + "&effective=T"
    } else if (this.data1_parmKey === 'STT') {// 盘点清单编号
      if (this.searchData['minDocDate'] == undefined || this.searchData['maxDocDate'] == undefined) {
        this.searchData['minDocDate'] = ''
        this.searchData['maxDocDate'] = ''
      }
      if (this.warehCode !== '') {
        this.searchData['warehCode'] = this.warehCode
        para = "&sttNum=" + this.searchData['sttNum'] + "&minDocDate=" + this.searchData['minDocDate'] + "&maxDocDate=" + this.searchData['maxDocDate'] + "&warehCode=" + this.searchData['warehCode'] + "&progress=" + this.searchData['progress']
      } else {
        para = "&sttNum=" + this.searchData['sttNum'] + "&minDocDate=" + this.searchData['minDocDate'] + "&maxDocDate=" + this.searchData['maxDocDate'] + "&warehCode=" + this.searchData['warehCode'] + "&progress=" + this.searchData['progress']
      }
    } else if (this.data1_parmKey === 'SYS_ROLE') {// 角色
      para = '&roleId=' + this.searchData['roleId'] + '&description=' + this.searchData['description']
    } else if (this.data1_parmKey === 'PPR_BY_PUC') {// 关联采购合同
      if (this.searchData['startTime'] == undefined || this.searchData['endTime'] == undefined) {
        this.searchData['startTime'] = ''
        this.searchData['endTime'] = ''
      }
      para = '&pucNum=' + this.searchData['pucNum'] + '&vdrWarehCode=' + this.searchData['vdrWarehCode'] + '&vdeWarehCode='
        + this.searchData['vdeWarehCode'] + '&startTime=' + this.searchData['startTime'] + '&endTime=' + this.searchData['endTime']
    } else if (this.data1_parmKey === 'PPR_GRN') {// 关联入库单
      if (this.searchData['startTime'] == undefined || this.searchData['endTime'] == undefined) {
        this.searchData['startTime'] = ''
        this.searchData['endTime'] = ''
      }
      para = '&grnNum=' + this.searchData['grnNum'] + '&startTime=' + this.searchData['startTime'] + '&endTime=' + this.searchData['endTime']
    } else if (this.data1_parmKey === 'PMN') {// 预付款单号
      if (this.searchData['startTime'] == undefined || this.searchData['endTime'] == undefined) {
        this.searchData['startTime'] = ''
        this.searchData['endTime'] = ''
      }
      para = '&pmnNum=' + this.searchData['pmnNum'] + '&vdeWarehCode=' + this.searchData['startTime'] + '&endTime=' + this.searchData['endTime']
    } else if (this.data1_parmKey === 'PPR') {// 采购付款申请单
      if (this.searchData['startTime'] == undefined || this.searchData['endTime'] == undefined) {
        this.searchData['startTime'] = ''
        this.searchData['endTime'] = ''
      }
      para = '&pprNum=' + this.searchData['pprNum'] + '&venderCode=' + this.searchData['venderCode'] + '&startTime=' + this.searchData['startTime'] + '&endTime=' + this.searchData['endTime']
    } else if (this.data1_parmKey === 'DOMAIN_ACCREDIT_OPTION') {// 授权领域
      para = '&domainId=' + this.searchData['domainId'] + '&unitName=' + this.searchData['unitName']
    } else if (this.data1_parmKey === 'DOMAIN_ACCREDIT_OPTION') {// 领域
      para = '&unitName=' + this.searchData['unitName'] + '&unitCode=' + this.searchData['unitCode']
    } else if (this.data1_parmKey === 'SLC') {// 销售合同号
      if (this.searchData['startTime'] == undefined || this.searchData['endTime'] == undefined) {
        this.searchData['startTime'] = ''
        this.searchData['endTime'] = ''
      }
      para = "&slcNum=" + this.searchData['slcNum'] + "&startTime=" + this.searchData['startTime'] + "&endTime=" + this.searchData['endTime'] + "&vendeeCode=" + this.searchData['vendeeCode'] + "&vdeWarehCode=" + this.searchData['vdeWarehCode'] + "&vdrWarehCode=" + this.searchData['vdrWarehCode'] + "&progress=" + this.searchData['progress']
    } else if (this.data1_parmKey === 'PROD_CLS') {// 套装代码
      if (this.searchData['prodClsCode'] == "" && this.searchData['prodName'] == "" && this.searchData['inputCode']=="") {
        layer.msg("必须输入搜索参数！");
      } 
      else {
        para = "&prodClsCode=" + this.searchData['prodClsCode'] + "&prodName=" + this.searchData['prodName'] + "&inputCode=" + this.searchData['inputCode'] + "&prodCatId=null"
      }
    } else if (this.data1_parmKey === 'PRC') {// 退购合同号
      if (this.searchData['startTime'] == undefined || this.searchData['endTime'] == undefined) {
        this.searchData['startTime'] = ''
        this.searchData['endTime'] = ''
      }
      para = "&prcNum=" + this.searchData['prcNum'] + "&startTime=" + this.searchData['startTime'] + "&endTime=" + this.searchData['endTime'] + "&venderNum=" + this.searchData['venderNum'] + "&vdrWarehNum=" + this.searchData['vdrWarehNum'] + "&vdeWarehNum=" + this.searchData['vdeWarehNum'] + "&progress=" + this.searchData['progress']
    } else if (this.data1_parmKey === '未有动态列') {// 组织筛选
      para = "&unitCode=" + this.searchData['unitCode'] + "&unitName=" + this.searchData['unitName']
    } else if (this.data1_parmKey === 'SYS_CUT_DOMAIN') {// 切换领域
      para = "&domainId=" + this.searchData['domainId'] + "&unitName=" + this.searchData['unitName']
    } else if (this.data1_parmKey === 'SYS_PRIVILEGE') {// 权限
      para = "&privId=" + this.searchData['privId'] + "&description=" + this.searchData['description'] + "&privType=" + this.searchData['privType']
    } else if (this.data1_parmKey === 'UNIT_DOMAIN') {// 设置密码--领域Id
      para = "&unitCode=" + this.searchData['unitCode'] + "&unitName=" + this.searchData['unitName'] + "&domainId=" + this.searchData['domainId']
    } else if (this.data1_parmKey === 'PRD_CYCLE_PARAM') {// 商品周期动作参数配置弹窗
      para = '&actionId=' + this.searchData['actionId'] + '&parameterName=' + this.searchData['parameterName']
    } else if (this.data1_parmKey === 'UNIT_PARAMETER') {// 领域组织参数
      para = '&parmId=' + this.searchData['parmId'] + '&description=' + this.searchData['description']
    }else if (this.data1_parmKey === 'SWITCH_DOMAIN') {// 切换组织
      para = '&parmId=' + this.searchData['parmId'] + '&description=' + this.searchData['description']
    }
    this.listTable(this.popupUrl + para);
  }


  listTable(url): void {
    setTimeout(() => {
      layui.use(['table',  'laydate'], (obj) => {
        var  table = layui.table,  laydate = layui.laydate;
        //数据表格实例化			
        var tab = this.utilService.getTable(url, '#' + this.tableId, this.field1)
        tab['title'] = '数据表'
        if (this.popupCheck !== '0') {
          tab['toolbar'] = '#' + this.tableId + '2';
          tab['defaultToolbar'] = [];
          tab["done"] = (res) => {
            this.utilService.checkboxClick('nz-modal', this.tableId);
            this.utilService.tdTitle()
          }
        }else{
          tab["done"] = (res) => {
            this.utilService.tdTitle()
          }
        }
        table.render(tab);
        //监听行单击事件row   监听行双击事件rowDouble
        table.on('row(' + this.tableId + ')', (obj) => {
          obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');//标注选中样式
        });
        table.on('rowDouble(' + this.tableId + ')', (obj) => {
          if (this.popupCheck === '0') {//单选
            this.popupHide();
            for (var x in obj.data) {
              obj.data[x] = obj.data[x] === undefined ? '' : obj.data[x] === null ? '' : obj.data[x];
            }
            this.outer.emit(obj.data);
          }
        });
        //头工具栏事件
        table.on('toolbar(' + this.tableId + ')', (obj) => {
          var checkStatus = table.checkStatus(obj.config.id);
          switch (obj.event) {
            case 'getCheckData':
              var data = checkStatus.data;
              if (this.popupCheck === '1') {// 多选原值返回
                this.outer.emit(data);
              } else {// 多选赋值字段分割处理后返回
                if (data.length > 0) {
                  let e = '';
                  for (let i = 0; i < data.length; i++) {
                    e = e + data[i][this.popupCheck] + ',';
                  }
                  this.outer.emit(e.substring(0, e.length - 1));
                } else {
                  layer.msg('请选择数据后操作！');
                }
              }
              this.popupHide();
              break;
          };
        });
      });
    }, 50);
  }

  privIds = this.interfaceService.GetQueryString("privId")
  //动态弹窗公用
  @ViewChild('popupChild1') popup: any;
  popupId;
  /**
   * 
   * @param id 弹窗标识
   * @param type 弹窗类型
   * @param key 弹窗动态列标识
   * @param title 弹窗文字
   * @param value 验证数值（可选参数，传递正常参数为验证数据模式）
   */
  parm
  isPopup = false;
  popupTable(id, type, key, title, value?): void {
    this.isPopup = true;
    this.popupId = id;
    var judge = value === undefined ? 0 : 1;
    var operation = 'S'
    if (this.popupId == 1 || this.popupId == 3) {
      this.parm = '?switchUnitId=' + this.switchUnitId + '&unitType=' + type + '&privId=' + this.privIds + '&operation=' + operation + '&judge=' + judge;
    } else if (this.popupId == 2) {
      if (this.utilService.patrn.test(this.searchData['venderNum']) && this.searchData['venderNum'] != null) {
        this.parm = '?switchUnitId=' + this.searchData['venderId'] + '&unitType=' + type + '&privId=' + this.privIds + '&operation=' + operation + '&judge=' + judge;
      } else {
        this.parm = '?switchUnitId=' + this.switchUnitId + '&unitType=' + type + '&privId=' + this.privIds + '&operation=' + operation + '&judge=' + judge;
      }
    } else if (this.popupId == 4 || this.popupId == 5) {
      this.parm = '?switchUnitId=' + this.switchUnitId + '&unitType=' + type + '&privId=' + this.privIds + '&operation=' + operation + '&judge=' + judge;
    } else if (this.popupId == 6) {
      if (this.utilService.patrn.test(this.searchData['vendeeNum']) && this.searchData['vendeeNum'] != null) {
        this.parm = '?switchUnitId=' + this.searchData['vendeeId'] + '&unitType=' + type + '&privId=' + this.privIds + '&operation=' + operation + '&judge=' + judge;
      } else {
        this.parm = '?switchUnitId=' + this.switchUnitId + '&unitType=' + type + '&privId=' + this.privIds + '&operation=' + operation + '&judge=' + judge;
      }
    } else if (this.popupId == 7) {
      this.parm = '?switchUnitId=' + this.switchUnitId + '&unitType=' + type + '&privId=' + this.privIds + '&operation=' + operation + '&judge=' + judge;
    } else if (this.popupId == 8) {
      this.parm = '?switchUnitId=' + this.switchUnitId + '&unitType=' + type + '&privId=' + this.privIds + '&operation=' + operation + '&judge=' + judge;
    } else if (this.popupId == 9) {
      this.parm = '?switchUnitId=' + this.switchUnitId + '&unitType=' + type + '&privId=' + this.privIds + '&operation=' + operation + '&judge=' + judge;
    } else if (this.popupId == 10) {
      this.parm = '?switchUnitId=' + this.switchUnitId + '&unitType=' + type + '&privId=' + this.privIds + '&operation=' + operation + '&judge=' + judge;
    } else if (this.popupId == 11) {
      this.parm = '?switchUnitId=' + this.switchUnitId + '&unitType=' + type + '&privId=' + this.privIds + '&operation=' + operation + '&judge=' + judge;
    } else if (this.popupId == 12) {
      if (this.utilService.patrn.test(this.searchData['vendeeNum']) && this.searchData['vendeeNum'] != null) {
        this.parm = '?switchUnitId=' + this.searchData['vendeeId'] + '&unitType=' + type + '&privId=' + this.privIds + '&operation=' + operation + '&judge=' + judge;
      } else {
        this.parm = '?switchUnitId=' + this.switchUnitId + '&unitType=' + type + '&privId=' + this.privIds + '&operation=' + operation + '&judge=' + judge;
      }
    } else if (this.popupId == 13) {
      this.parm = '?switchUnitId=' + this.switchUnitId + '&unitType=' + type + '&privId=' + this.privIds + '&operation=' + operation + '&judge=' + judge;
    } else if (this.popupId == 14) {
      this.parm = '?switchUnitId=' + this.switchUnitId + '&unitType=' + type + '&privId=' + this.privIds + '&operation=' + operation + '&judge=' + judge;
    } else if (this.popupId == 15) {
      if (this.utilService.patrn.test(this.searchData['venderNum']) && this.searchData['venderNum'] != null) {
        this.parm = '?switchUnitId=' + this.searchData['venderId'] + '&unitType=' + type + '&privId=' + this.privIds + '&operation=' + operation + '&judge=' + judge;
      } else {
        this.parm = '?switchUnitId=' + this.switchUnitId + '&unitType=' + type + '&privId=' + this.privIds + '&operation=' + operation + '&judge=' + judge;
      }
    } else if (this.popupId == 16) {
      this.parm = '?switchUnitId=' + this.switchUnitId + '&unitType=' + type + '&privId=' + this.privIds + '&operation=' + operation + '&judge=' + judge;
    }
    setTimeout(() => {
      this.popup.tableShow(key, this.parm, title);
    }, this.utilService.setTime1);
  }

  popupParent(e) {
    if (this.popupId === 1) {
      this.searchData['venderNum'] = e.unitCode;
      this.searchData['venderId'] = e.unitId
    } else if (this.popupId === 2) {
      this.searchData['vdrWarehNum'] = e.unitCode;
    } else if (this.popupId === 3) {
      this.searchData['vdeWarehNum'] = e.unitCode;
    } else if (this.popupId === 4) {
      this.searchData['vendeeNum'] = e.unitCode;
      this.searchData['vendeeId'] = e.unitId
    } else if (this.popupId === 5) {
      this.searchData['vdrWarehNum'] = e.unitCode;
    } else if (this.popupId === 6) {
      this.searchData['vdeWarehNum'] = e.unitCode;
    } else if (this.popupId === 7) {
      this.searchData['warehCode'] = e.unitCode;
    } else if (this.popupId === 8) {
      this.searchData['vdrWarehCode'] = e.unitCode;
    } else if (this.popupId === 9) {
      this.searchData['vdeWarehCode'] = e.unitCode;
    } else if (this.popupId === 10) {
      this.searchData['venderCode'] = e.unitCode;
    } else if (this.popupId === 11) {
      this.searchData['vendeeNum'] = e.unitCode;
      this.searchData['vendeeId'] = e.unitId;
    } else if (this.popupId === 12) {
      this.searchData['vdeWarehNum'] = e.unitCode;
    } else if (this.popupId === 13) {
      this.searchData['vdrWarehNum'] = e.unitCode;
    } else if (this.popupId === 14) {
      this.searchData['venderNum'] = e.unitCode;
      this.searchData['venderId'] = e.unitId;
    } else if (this.popupId === 15) {
      this.searchData['vdrWarehNum'] = e.unitCode;
    } else if (this.popupId === 16) {
      this.searchData['vdeWarehNum'] = e.unitCode;
    }
  }


}
